#include "llvm/Linker.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/System/Path.h"
#include "llvm/PassManager.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Assembly/Parser.h"
#include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Streams.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include <iostream>
#include <fstream>
#include <memory>
#include "device_driver.h"

#define DEBUG_STR(s) printf("%s\n",input);
using namespace llvm;
//string device_driver(string);
		
std::string transform(std::string inputfilename,int argc,char ** argv)
{

	char *input;
	char *cmd;
	int i=0;
	input=(char *)malloc(inputfilename.length()+1);
	for (;i<inputfilename.length();i++)input[i]=inputfilename[i];
	input[i+1]='\0';
	char *ptx_c;
	ptx_c=(char *)malloc(255);
	DEBUG_STR(input);
	//getchar();
	ptx_c=device_driver(input);
	cmd=(char *)malloc(sizeof(char)*(strlen("clang %s -emit-llvm -c -o driver.o")+strlen(ptx_c))+1);
	sprintf(cmd,"clang %s -emit-llvm -c -o driver.o",ptx_c);
	system(cmd);	
	free(cmd);
	free(ptx_c);
	free(input);

	
	//bc_generator(inputfilename,"ptx_driver.o",argc,argv);
	return inputfilename;
}
